﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using System.Globalization;

namespace BSC_OTC_Management.Forms
{
    public partial class FrmView : Form
    {
        #region khai bao bien

        string _formName = "";
        string _formTitle = "";
        int sttTruyVan = 0;
        bool _truyvan = false; //DatNT add for form_ChuyenNhuong
        DataTable tableSearch = new DataTable("tableSearch");
        Hashtable listTieuChi = new Hashtable();
        Hashtable listDS_DK_TimKiem = new Hashtable();
        Hashtable listDS_Duyet = new Hashtable();
        DataTable _tableView = new DataTable("SEARCHFLD");
        DataTable _tableTieuChi = new DataTable("SEARCHFLD");
        Code.StaticVariable _code = new Code.StaticVariable();
        Code.CL_Ultility _cl = new Code.CL_Ultility();
        string _operator = "";
        string _fieldtype = "";
        string _lookupcmdsql = "";
        DataTable _tableResult = new DataTable("noname");
        //int _currentSelectIndex = 0; //set mặc định row 0 luôn được chọn.
        #endregion

        #region load du lieu

        private void FillTieuChi()
        {
            foreach (DataRow row in _tableTieuChi.Rows)
            {
                string key = String.Concat(row["fldcd"].ToString().Trim(), '.', row["fieldcode"].ToString().Trim(), "@@@", row["fieldtype"].ToString());
                string value = row["fieldname"].ToString();
                this.listTieuChi.Add(key, value);
                this.cbbTieuChi.Items.Add(value);
            }

            //DATNT: chọn item đầu tiên đổ cho combobox
            if (listTieuChi.Count > 0)
            {
                this.cbbTieuChi.SelectedIndex = 0;
            }

            //Create table search
            tableSearch = new DataTable("tableSearch");
            tableSearch.Columns.Add("COLUMNNAME");
            tableSearch.Columns.Add("PHEPTINH");
            tableSearch.Columns.Add("VALUE");
            tableSearch.Columns.Add("DATATYPE");
        }
        #endregion

        #region sự kiện

        public FrmView()
        {
            InitializeComponent();
        }

        public FrmView(string _e, string _formTitle)
        {
            InitializeComponent();
            this._formName = _e;
            this._formTitle = _formTitle;
            this.Text = _formTitle;
            _tableView = _code._services.GetViewBy_SearchCode(_formName);
            _tableTieuChi = _code._services.GetPhepToanBy_SearchCode(_formName);
            this.dgvResult.CellFormatting += new DataGridViewCellFormattingEventHandler(dgvResult_CellFormatting);
            this.dgvResult.RowTemplate.Height = 18;
            FillTieuChi();
            ShowHide_FunctionByPermission();
            // nếu là gọi form bt thì chỉ show ra sự kiện cell click  để hiện nút duyêt hay không
            this.dgvResult.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvResult_CellClick);
        }

        //DatNT: chuyển từ form khac xem truy van
        public FrmView(string _e, string _formTitle, bool _truyvan)
        {
            InitializeComponent();
            //từ from Chuyển Nhượng
            this._truyvan = _truyvan;
            //khởi tạo
            this._formName = _e;
            this._formTitle = _formTitle;
            this.Text = _formTitle;
            _tableView = _code._services.GetViewBy_SearchCode(_formName);
            _tableTieuChi = _code._services.GetPhepToanBy_SearchCode(_formName);
            this.dgvResult.CellFormatting += new DataGridViewCellFormattingEventHandler(dgvResult_CellFormatting);
            this.dgvResult.RowTemplate.Height = 18;
            FillTieuChi();
            if (GetPermission_byControl(btnTimKiem))
                this.btnTimKiem.Enabled = true;
            // nếu là gọi form truy vấn thì chỉ show ra sự kiện cell double click
            this.dgvResult.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvResult_CellDoubleClick);
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.Escape)
            {
                this.Close();
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            if (this.dgvResult.RowCount > 0)
            {
                Code.ExportUtility _ExportExcel = new Code.ExportUtility();
                _ExportExcel.Export(this.dgvResult);
            }
        }

        private void cbbTieuChi_SelectedIndexChanged(object sender, EventArgs e)
        {
            // lấy phép toán tương ứng với tiêu chí
            foreach (DataRow row in _tableTieuChi.Rows)
            {
                if (cbbTieuChi.Text == row["FIELDNAME"].ToString())
                {
                    _operator = row["OPERATOR"].ToString();
                    _fieldtype = row["FIELDTYPE"].ToString();
                    _lookupcmdsql = row["LOOKUPCMDSQL"].ToString();
                }
            }

            // xoa het Phep toan, add lại
            this.cbbPhepToan.Items.Clear();
            if (_operator.Contains(","))
            {
                string[] operator_mini = _operator.Split(',');
                for (int i = 0; i < operator_mini.Length; i++)
                {
                    cbbPhepToan.Items.Add(operator_mini[i].Trim());
                }
                this.cbbPhepToan.SelectedIndex = 0;
            }

            // Ẩn hiện giá trị theo FieldType 
            ShowHide_GiaTri(_fieldtype, _lookupcmdsql);
        }

        private void btnTruyenSang_Click(object sender, EventArgs e)
        {
            if (txtGiaTriTimKiem.Text.Trim().Length > 0 || this.dtpGiaTri.Text != "" || cbbGiaTri.Text != "")
            {
                // Gán giá trị tìm kiếm vào mảng
                foreach (DictionaryEntry item in this.listTieuChi)
                {
                    if (item.Value.ToString() == this.cbbTieuChi.Text)
                    {
                        //DATNT: kiểm tra phép toán điều kiện là gì
                        switch (cbbPhepToan.Text)
                        {
                            case "LIKE":
                                //this.listDS_DK_TimKiem.Add(item.Key, item.Key + " " + this.cbbPhepToan.Text + " '%" + this.txtGiaTriTimKiem.Text + "%'");
                                this.Like(item);
                                break;
                            default:
                                //this.listDS_DK_TimKiem.Add(item.Key, item.Key + " " + this.cbbPhepToan.Text + " '" + this.txtGiaTriTimKiem.Text + "'");
                                this.Equal(item);
                                break;
                        }
                        this.Add();
                        //end DATNT
                    }
                }
                // them vao phan hien thi
                //DatNT: remove this.clbDanhSachDieuKien.Items.Clear();
                //this.clbDanhSachDieuKien.Items.Add(this.cbbTieuChi.Text + " " + this.cbbPhepToan.Text + " '" + this.txtGiaTriTimKiem.Text + "'", true);
                this.btnTimKiem.Focus();
            }
        }

        private void Like(DictionaryEntry item)
        {

            string[] strKey = item.Key.ToString().Split(new string[] { "@@@" }, StringSplitOptions.None);

            DataRow row = tableSearch.NewRow();
            row["COLUMNNAME"] = strKey[0];
            row["PHEPTINH"] = this.cbbPhepToan.Text.Trim();
            if (this._fieldtype == "D")
            {
                row["VALUE"] = this.dtpGiaTri.Value.ToString("dd/MM/yyyy");
            }
            else
            {
                if ((_lookupcmdsql == "") && this._fieldtype == "C")
                    row["VALUE"] = this.txtGiaTriTimKiem.Text.ToUpper();
                else
                    row["VALUE"] = ((KeyValuePair<string, string>)cbbGiaTri.SelectedItem).Key;
            }
            row["DATATYPE"] = strKey[1];
            tableSearch.Rows.Add(row);
            /*if (this.listDS_DK_TimKiem.ContainsKey(item.Key) == false)
            {
                switch (this._fieldtype)
                {
                    case "C":
                        if (_lookupcmdsql == "")
                        {
                            listDS_DK_TimKiem.Add(item.Key, this.cbbPhepToan.Text + "@@@" + this.txtGiaTriTimKiem.Text.ToUpper());
                        }
                        else
                            listDS_DK_TimKiem.Add(item.Key, this.cbbPhepToan.Text + "@@@" + ((KeyValuePair<string, string>)cbbGiaTri.SelectedItem).Key);
                        break;
                    case "D":
                        this.listDS_DK_TimKiem.Add(item.Key, this.cbbPhepToan.Text + "@@@" + this.dtpGiaTri.Value.ToString("dd/MM/yyyy"));
                        break;
                    default:
                        break;
                }
            }
            else
            {
                switch (this._fieldtype)
                {
                    case "C":
                        if (_lookupcmdsql == "")
                        {
                            
                            //listDS_DK_TimKiem.Add(item.Key, this.cbbPhepToan.Text + "@@@" + this.txtGiaTriTimKiem.Text.ToUpper());
                            listDS_DK_TimKiem[item.Key] += "@@@" + this.cbbPhepToan.Text + "@@@" + this.txtGiaTriTimKiem.Text.ToUpper();
                        }
                        else
                            listDS_DK_TimKiem[item.Key] += "@@@" +this.cbbPhepToan.Text + "@@@" + ((KeyValuePair<string, string>)cbbGiaTri.SelectedItem).Key;
                        break;
                    case "D":
                        listDS_DK_TimKiem[item.Key] += "@@@" + this.cbbPhepToan.Text + "@@@" + this.dtpGiaTri.Value.ToString("dd/MM/yyyy");
                        break;
                    default:
                        break;
                }
            }*/
        }

        private void Equal(DictionaryEntry item)
        {
            string[] strKey = item.Key.ToString().Split(new string[] { "@@@" }, StringSplitOptions.None);

            DataRow row = tableSearch.NewRow();
            row["COLUMNNAME"] = strKey[0];
            row["PHEPTINH"] = this.cbbPhepToan.Text.Trim();
            if (this._fieldtype == "D")
            {
                row["VALUE"] = this.dtpGiaTri.Value.ToString("dd/MM/yyyy");
            }
            else
            {
                if ((_lookupcmdsql == "") && this._fieldtype == "C")
                    row["VALUE"] = this.txtGiaTriTimKiem.Text.ToUpper();
                else
                    row["VALUE"] = ((KeyValuePair<string, string>)cbbGiaTri.SelectedItem).Key;
            }
            row["DATATYPE"] = strKey[1];
            tableSearch.Rows.Add(row);
            /*if (this.listDS_DK_TimKiem.ContainsKey(item.Key) == false)
            {
                switch (this._fieldtype)
                {
                    case "C":
                        if (_lookupcmdsql == "")
                        {
                            listDS_DK_TimKiem.Add(item.Key, this.cbbPhepToan.Text + "@@@" + this.txtGiaTriTimKiem.Text.ToUpper());
                        }
                        else
                            listDS_DK_TimKiem.Add(item.Key, this.cbbPhepToan.Text + "@@@" + ((KeyValuePair<string, string>)cbbGiaTri.SelectedItem).Key);
                        break;
                    case "D":
                        this.listDS_DK_TimKiem.Add(item.Key, this.cbbPhepToan.Text + "@@@" + this.dtpGiaTri.Value.ToString("dd/MM/yyyy"));
                        break;
                    default:
                        break;
                }
            }
            else
            {
                switch (this._fieldtype)
                {
                    case "C":
                        if (_lookupcmdsql == "")
                        {

                            //listDS_DK_TimKiem.Add(item.Key, this.cbbPhepToan.Text + "@@@" + this.txtGiaTriTimKiem.Text.ToUpper());
                            listDS_DK_TimKiem[item.Key] += "@@@" + this.cbbPhepToan.Text + "@@@" + this.txtGiaTriTimKiem.Text.ToUpper();
                        }
                        else
                            listDS_DK_TimKiem[item.Key] += "@@@" + this.cbbPhepToan.Text + "@@@" + ((KeyValuePair<string, string>)cbbGiaTri.SelectedItem).Key;
                        break;
                    case "D":
                        listDS_DK_TimKiem[item.Key] += "@@@" + this.cbbPhepToan.Text + "@@@" + this.dtpGiaTri.Value.ToString("dd/MM/yyyy");
                        break;
                    default:
                        break;
                }
            }*/
        }

        private void Add()
        {
            if (this.txtGiaTriTimKiem.Visible)
                this.clbDanhSachDieuKien.Items.Add(this.cbbTieuChi.Text + " " + this.cbbPhepToan.Text + " '" + this.txtGiaTriTimKiem.Text + "'", true);
            else
            {
                if(cbbGiaTri.Visible)
                    this.clbDanhSachDieuKien.Items.Add(this.cbbTieuChi.Text + " " + this.cbbPhepToan.Text + " '" + this.cbbGiaTri.Text + "'", true);
                else
                    this.clbDanhSachDieuKien.Items.Add(this.cbbTieuChi.Text + " " + this.cbbPhepToan.Text + " '" + this.dtpGiaTri.Text + "'", true);
            }

        }

        private void btnTruyenVe_Click(object sender, EventArgs e)
        {
            if (this.clbDanhSachDieuKien.SelectedIndex >= 0)
            {
                //DATNT: bỏ trong mảng tìm kiếm
                // Gán giá trị tìm kiếm vào mảng
                //foreach (DictionaryEntry item in this.listTieuChi)
                //{
                //    if (this.clbDanhSachDieuKien.SelectedItem.ToString().Contains(item.Value.ToString()))
                //    {
                        tableSearch.Rows.Remove(tableSearch.Rows[this.clbDanhSachDieuKien.SelectedIndex]);
                        /*this.listDS_DK_TimKiem.Remove(item.Key);*/
                        //end DATNT
                //    }
                //}

                // bỏ phần hiển thị
                this.clbDanhSachDieuKien.Items.Remove(this.clbDanhSachDieuKien.SelectedItem);
            }
        }

        private void btnTruyenVeHet_Click(object sender, EventArgs e)
        {
            this.clbDanhSachDieuKien.Items.Clear();
            this.listDS_DK_TimKiem.Clear();
            this.tableSearch.Clear();
        }

        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            /*string str = "";
            DataTable table = new DataTable("noname");
            table.Columns.Add("COLUMNNAME");
            table.Columns.Add("PHEPTINH");
            table.Columns.Add("VALUE");
            table.Columns.Add("DATATYPE");
            if (this.clbDanhSachDieuKien.Items.Count > 0)
            {
                foreach (DictionaryEntry entry in this.listDS_DK_TimKiem)
                {
                    string[] strKey = entry.Key.ToString().Split(new string[] { "@@@" }, StringSplitOptions.None);
                    string[] strArray = entry.Value.ToString().Split(new string[] { "@@@" }, StringSplitOptions.None);

                    //neu co nh hon 1 gia tri tim kiem thi tuc la dang tim kiem 1 key nh gia tri
                    for (int i = 0; i < strArray.Length; i += 2)
                    {
                        DataRow row = table.NewRow();
                        row["COLUMNNAME"] = strKey[0];
                        row["PHEPTINH"] = strArray[i];
                        if (strKey[1] == "D")
                        {
                            DateTime time = DateTime.ParseExact(strArray[i+1], "dd/MM/yyyy", CultureInfo.InvariantCulture);
                            row["VALUE"] = time.ToString("dd/MM/yyyy");
                        }
                        else
                            row["VALUE"] = strArray[i+1];
                        row["DATATYPE"] = strKey[1];
                        table.Rows.Add(row);
                    }
                }
            }*/
            try
            {
                this._tableResult = this._code._services.SearchView_ByParameters(this._formName, tableSearch);
                //an tim kiem thi cac nut check x bi xoa nen can clear() danh sach duyet
                this.listDS_Duyet.Clear();
                //
                this.ShowResult(this._tableResult);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Code.StaticVariable.messeseboxLuuY);
            }

        }

        private void btnAddNew_Click(object sender, EventArgs e)
        {
            if (_formName == "BSC_TBL_NDDTCPH")
            {
                Forms.Frm_GanNDD_HDDL _frm = new Frm_GanNDD_HDDL(_formName,
                    this._formTitle,
                    Code.StaticVariable.function_AddNew,
                    "",
                    "");
                _frm.ShowDialog();
            }
            else
            {
                if (_formName == "BSC_TBL_CONGVIEC")
                {
                    Forms.Form_AddNew_CongViec _Form_AddNew_CongViec = new Form_AddNew_CongViec(_formName,
                    this._formTitle,
                    Code.StaticVariable.function_AddNew,
                    "",
                    "");
                    _Form_AddNew_CongViec.ShowDialog();
                }
                else
                {
                    Frm_AddEdit _Frm_AddEdit = new Frm_AddEdit(_formName,
                        this._formTitle,
                        Code.StaticVariable.function_AddNew,
                        "",
                        "");
                    _Frm_AddEdit.ShowDialog();
                }
            }
        }

        private void btnView_Click(object sender, EventArgs e)
        {
            if (this.dgvResult.SelectedRows.Count == 0)
            {
                MessageBox.Show(Code.StaticVariable.messeseboxPhaiChonDongDeThemSuaXoa);
            }
            else
            {
                // lấy ID của row được chọn
                string _id = this.dgvResult.SelectedRows[0].Cells[0].Value.ToString();
                string _CulumnName = this.dgvResult.Columns[0].Name;
                if (_formName == "BSC_TBL_NDDTCPH")
                {
                    Forms.Frm_GanNDD_HDDL _frm = new Frm_GanNDD_HDDL(_formName, this._formTitle, Code.StaticVariable.function_View, _id, _CulumnName);
                    _frm.ShowDialog();
                }
                else
                {
                    Frm_AddEdit _Frm_AddEdit = new Frm_AddEdit(_formName, this._formTitle, Code.StaticVariable.function_View, _id, _CulumnName);
                    _Frm_AddEdit.ShowDialog();
                }
            }
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (this.dgvResult.SelectedRows.Count == 0)
            {
                MessageBox.Show(Code.StaticVariable.messeseboxPhaiChonDongDeThemSuaXoa);
            }
            else
            {
                /* lấy ID của row được chọn*/
                //this.dgvResult.Rows[this._currentSelectIndex].Selected = true;
                //phương thức selected row lấy ra các row được chọn, ở đây có 1 row nên lấy row[0]
                string _id = this.dgvResult.SelectedRows[0].Cells[0].Value.ToString();

                //lấy column name của row đc chọn
                string _CulumnName = this.dgvResult.Columns[0].Name;
                int check = _code._services.CheckApprove(_formName, _CulumnName, _id);
                if (check == (int)Code.StaticVariable.approveCase.DaXoa || check == (int)Code.StaticVariable.approveCase.DuyetXoa)
                    return;
                if (_formName == "BSC_TBL_NDDTCPH")
                {
                    Forms.Frm_GanNDD_HDDL _frm = new Frm_GanNDD_HDDL(_formName,
                        this._formTitle,
                        Code.StaticVariable.function_Edit,
                        _id,
                        _CulumnName);
                    _frm.ShowDialog();
                    btnTimKiem_Click(sender, e);
                }
                else
                {
                    Frm_AddEdit _Frm_AddEdit = new Frm_AddEdit(_formName,
                        this._formTitle,
                        Code.StaticVariable.function_Edit,
                        _id,
                        _CulumnName);
                    _Frm_AddEdit.ShowDialog();
                    btnTimKiem_Click(sender, e);
                }
                //this.dgvResult.Rows[this._currentSelectIndex].Selected = true;
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.dgvResult.SelectedRows.Count == 0)
            {
                MessageBox.Show(Code.StaticVariable.messeseboxPhaiChonDongDeThemSuaXoa);
            }
            else
            {
                // lấy ID của row được chọn
                string _id = this.dgvResult.SelectedRows[0].Cells[0].Value.ToString();
                string _ColumnName = this.dgvResult.Columns[0].Name;
                if (MessageBox.Show(Code.StaticVariable.messeseboxXoaRow, this._formTitle, MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                {
                    //check trạng thái duyệt
                    int check = _code._services.CheckApprove(_formName, _ColumnName, _id);
                    //đã xoá, duyệt xoá thì ko cần xoá
                    if (check != 2 && check != 4)
                    {
                        //cần chờ duyệt trước khi xoá
                        bool b = _code._services.Approve_Data(_formName, _ColumnName, _id, (int)Code.StaticVariable.approveCase.DuyetXoa);
                        if (b)
                        {
                            //lưu vết giao dịch
                            _code._services.WritetoTLLOG(Code.StaticVariable.userID,
                                                        "",
                                                        Code.StaticVariable.menu_Code,
                                                        _cl.Current_DATE("dd/MM/yyyy"),
                                                        "",
                                                        _cl.Current_DATE("hh:mm:ss"),
                                                        "",
                                                        (int)Code.StaticVariable.approveCase.ChuaDuyet + "",
                                                        Code.StaticVariable.function_Delete,
                                                        _id,
                                                        "");
                            //luu vet nguoi thuc hien
                            _code._services.Update_Last_Change(_formName, _id, Code.StaticVariable.userID);
                            MessageBox.Show(Code.StaticVariable.messeseboxChuaDuyet, Code.StaticVariable.messeseboxLuuY);
                        }
                        else
                        {
                            //ghi lỗi ra logError.log

                            //
                            MessageBox.Show(Code.StaticVariable.messeseboxLoi, Code.StaticVariable.messeseboxLuuY);
                        }
                        btnTimKiem_Click(sender, e);
                    }
                }
            }
        }

        // hiện ra nút duyệt hay ko ?
        private void dgvResult_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                //kiểm tra xem có quyền duyệt hay ko?
                bool p = GetPermission_byControl(this.btnApprove);
                if (p == true)
                {//có quyền duyệt mới thực hiện đoạn code này
                    //this._currentSelectIndex = this.dgvResult.CurrentCell.RowIndex;
                    string _id = this.dgvResult.SelectedRows[0].Cells[0].Value.ToString();
                    string _ColumnName = this.dgvResult.Columns[0].Name;
                    int duyet = _code._services.CheckApprove(_formName, _ColumnName, _id);

                    if (duyet == 0 || duyet == 2)
                        btnApprove.Enabled = true;
                    else
                        btnApprove.Enabled = false;
                }
                //không có quyền bỏ qua
            }
            catch (Exception ex)
            {
                btnApprove.Enabled = false;
            }
        }

        //DatNT double click để trả về giá trị bản ghi theo click chuột, dùng khi truy vấn từ form khác
        private void dgvResult_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            string _id = this.dgvResult.SelectedRows[0].Cells[0].Value.ToString();
            string _ColumnName = this.dgvResult.Columns[0].Name;
            int duyet = _code._services.CheckApprove(_formName, _ColumnName, _id);
            if (this._truyvan)
            {
                if (duyet == (int)Code.StaticVariable.approveCase.DaDuyet)
                {
                    Code.StaticVariable.id_TruyVan = null;
                    Code.StaticVariable.id_TruyVan = dgvResult.CurrentRow.Cells[0].Value.ToString();
                    DataTable dt = new DataTable();
                    for (int i = 0; i < dgvResult.Columns.Count; i++)
                    {
                        DataColumn dc = new DataColumn(dgvResult.Columns[i].Name, typeof(String));
                        dt.Columns.Add(dc);
                    }

                    DataRow row = dt.NewRow();
                    for (int i = 0; i < dgvResult.Columns.Count; i++)
                    {
                        row[i] = dgvResult.CurrentRow.Cells[i].Value.ToString();
                    }

                    dt.Rows.Add(row);
                    //đổ dữ liệu vào DTable của form cần truy vấn
                    Code.StaticVariable.DTable = new DataTable("noname");
                    Code.StaticVariable.DTable = dt;
                    this.Close();
                }
                else
                    if (duyet == (int)Code.StaticVariable.approveCase.DaXoa)
                        MessageBox.Show(Code.StaticVariable.messeseboxDaXoa, Code.StaticVariable.messeseboxLuuY);
                    else
                        MessageBox.Show(Code.StaticVariable.messeseboxChuaDuyet, Code.StaticVariable.messeseboxLuuY);
            }

        }

        //event menu select all click
        private void MenuSelectAll_Click(Object sender, System.EventArgs e)
        {
            //kiem tra danh sach select all co id da dc duyet ko?
            foreach (DataGridViewRow row in dgvResult.Rows)
            {
                string _id = row.Cells[0].Value.ToString();
                string _ColumnName = this.dgvResult.Columns[0].Name;
                //kiểm tra xem đã duyệt chưa?
                int check = _code._services.CheckApprove(_formName, _ColumnName, _id);
                if (check == (int)Code.StaticVariable.approveCase.DaDuyet)
                {
                    MessageBox.Show("Không thể chọn danh sách chứa bản ghi đã được duyệt!", Code.StaticVariable.messeseboxLuuY);
                    this.listDS_Duyet.Clear();
                    break;
                }

                if (!this.listDS_Duyet.Contains(_id))
                {
                    row.HeaderCell.Value = "X";
                    this.listDS_Duyet.Add(_id, _ColumnName);
                }
            }

            if (this.listDS_Duyet.Count > 0)
            {
                this.btnView.Enabled = false;
                this.btnEdit.Enabled = false;
                this.btnDelete.Enabled = false;
            }

        }

        //event menu deselect all click
        private void MenuDeSelectAll_Click(Object sender, System.EventArgs e)
        {
            if (this.listDS_Duyet.Count > 0)
            {
                //xoa het item trong danh sach
                this.listDS_Duyet.Clear();

                //enable cac button thì phải check lại quyền
                bool p = GetPermission_byControl(btnView);
                if (p == true)
                    this.btnView.Enabled = true;
                p = GetPermission_byControl(btnEdit);
                if (p == true)
                    this.btnEdit.Enabled = true;
                p = GetPermission_byControl(btnDelete);
                if (p == true)
                    this.btnDelete.Enabled = true;

                //load lai nut tim kiem
                this.btnTimKiem_Click(sender, e);
            }
        }

        private void dgvResult_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            //////
            if (e.Button == MouseButtons.Right)
            {
                ContextMenu m = new ContextMenu();
                m.MenuItems.Add(new MenuItem("Select All", MenuSelectAll_Click));
                m.MenuItems.Add(new MenuItem("DeSelect All", MenuDeSelectAll_Click));
                Rectangle r = dgvResult.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
                m.Show(dgvResult, new Point(r.Left + e.X, r.Top + e.Y));

            }
            else
            {
                string _id = this.dgvResult.SelectedRows[0].Cells[0].Value.ToString();
                string _ColumnName = this.dgvResult.Columns[0].Name;

                if (dgvResult.Rows[e.RowIndex].HeaderCell.Value == "X")
                {
                    dgvResult.Rows[e.RowIndex].HeaderCell.Value = "";
                    this.listDS_Duyet.Remove(_id);
                }
                else
                {
                    if (btnApprove.Enabled == true && !this.listDS_Duyet.Contains(_id))
                    {
                        dgvResult.Rows[e.RowIndex].HeaderCell.Value = "X";
                        this.listDS_Duyet.Add(_id, _ColumnName);
                    }
                }

                if (this.listDS_Duyet.Count > 0)
                {
                    this.btnView.Enabled = false;
                    this.btnEdit.Enabled = false;
                    this.btnDelete.Enabled = false;
                }
                else
                {
                    //enable cac button thì phải check lại quyền
                    bool p = GetPermission_byControl(btnView);
                    if (p == true)
                        this.btnView.Enabled = true;
                    p = GetPermission_byControl(btnEdit);
                    if (p == true)
                        this.btnEdit.Enabled = true;
                    p = GetPermission_byControl(btnDelete);
                    if (p == true)
                        this.btnDelete.Enabled = true;
                }
                dgvResult.RowHeadersWidth = 50;
                dgvResult.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
            }
            /////
        }

        private void txtGiaTriTimKiem_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.btnTruyenSang_Click(sender, e);
            }
        }

        // bỏ phần uncheck với danh sách tìm kiếm
        private void clbDanhSachDieuKien_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (e.NewValue == CheckState.Unchecked)
            {
                e.NewValue = CheckState.Checked;
            }
        }

        private void btnApprove_Click(object sender, EventArgs e)
        {
            try
            {
                string _id = "";
                string _ColumnName = "";
                //kiem tra xem duyệt lô hay duyệt tay?
                if (this.listDS_Duyet.Count == 0)
                {
                    // lấy ID của row được chọn
                    _id = this.dgvResult.SelectedRows[0].Cells[0].Value.ToString();
                    _ColumnName = this.dgvResult.Columns[0].Name;

                    //duyet
                    Approve(_ColumnName, _id);
                }
                else
                {
                    DialogResult dialog = MessageBox.Show(Code.StaticVariable.messeseboxDuyetAllRow, Code.StaticVariable.messeseboxLuuY, MessageBoxButtons.YesNo);

                    if (dialog == DialogResult.Yes)
                    {
                        foreach (DictionaryEntry item in listDS_Duyet)
                        {
                            _id = (string)item.Key;
                            _ColumnName = (string)item.Value;

                            //duyet
                            if (!ApproveAll(_ColumnName, _id))
                            {
                                this.listDS_Duyet.Clear();
                                MessageBox.Show(Code.StaticVariable.messeseboxDuyetThatBai, Code.StaticVariable.messeseboxLuuY);
                                btnTimKiem_Click(sender, e);
                                return;
                            }
                        }
                        this.listDS_Duyet.Clear();
                        MessageBox.Show(Code.StaticVariable.messeseboxDuyetAllThanhCong, Code.StaticVariable.messeseboxLuuY);
                    }
                    else
                        this.listDS_Duyet.Clear();
                }
                    /*    
                    //Hiển thị Dialog thông báo
                    DialogResult dialog = MessageBox.Show(Code.StaticVariable.messeseboxDuyetRow, Code.StaticVariable.messeseboxLuuY, MessageBoxButtons.YesNo);

                    if (dialog == DialogResult.Yes)
                    {
                        //kiểm tra xem đã duyệt chưa?
                        int check = _code._services.CheckApprove(_formName, _ColumnName, _id);
                        //dữ liệu chưa được duyệt
                        switch(check){
                            case (int)Code.StaticVariable.approveCase.ChuaDuyet: //chưa duyêt
                            
                                string _value = _ColumnName + "_" + _id;
                                DataTable _dt = new DataTable("duyetdata");
                                _dt = _cl._services.GetTableData_DuyetSua(_value, _formName);
                                if (_dt.Rows.Count > 0)//co du lieu da sua --> duyet sua
                                {
                                    Forms.Frm_Duyet _Frm_Duyet = new Frm_Duyet(_ColumnName, _id, _dt, Code.StaticVariable.function_Edit, _formName);
                                    _Frm_Duyet.ShowDialog();
                                }
                                else //ko co dl trong bang maintain_log --> them moi
                                {
                                    //lay thong tin them moi
                                    DataTable _dtAdd = new DataTable();
                                    for (int i = 0; i < dgvResult.Columns.Count; i++)
                                    {
                                        DataColumn dc = new DataColumn(dgvResult.Columns[i].Name, typeof(String));
                                        _dtAdd.Columns.Add(dc);
                                    }

                                    DataRow rowAdd = _dtAdd.NewRow();
                                    for (int i = 0; i < dgvResult.Columns.Count; i++)
                                    {
                                        rowAdd[i] = dgvResult.CurrentRow.Cells[i].Value.ToString();
                                    }
                                    _dtAdd.Rows.Add(rowAdd);

                                    //chuyen sang form duyet
                                    Forms.Frm_Duyet _Frm_DuyetThemMoi = new Frm_Duyet(_ColumnName, _id, _dtAdd, Code.StaticVariable.function_AddNew, _formName);
                                    _Frm_DuyetThemMoi.ShowDialog();

                                    btnTimKiem_Click(sender, e);
                                
                                }
                                btnTimKiem_Click(sender, e);
                                break;
                            case (int)Code.StaticVariable.approveCase.DaDuyet: //đã duyệt
                                MessageBox.Show(Code.StaticVariable.messeseboxDaDuyet, Code.StaticVariable.messeseboxLuuY);
                                break;
                            case (int)Code.StaticVariable.approveCase.DuyetXoa: //duyệt xoá
                                //thong tin xoa
                                DataTable _dtxoa = new DataTable();
                                for (int i = 0; i < dgvResult.Columns.Count; i++)
                                {
                                    DataColumn dc = new DataColumn(dgvResult.Columns[i].Name, typeof(String));
                                    _dtxoa.Columns.Add(dc);
                                }

                                DataRow row = _dtxoa.NewRow();
                                for (int i = 0; i < dgvResult.Columns.Count; i++)
                                {
                                    row[i] = dgvResult.CurrentRow.Cells[i].Value.ToString();
                                }

                                _dtxoa.Rows.Add(row);

                                //chuyen sang form duyet xóa
                                Forms.Frm_Duyet _Frm_DuyetXoa = new Frm_Duyet(_ColumnName, _id, _dtxoa, Code.StaticVariable.function_Delete, _formName);
                                _Frm_DuyetXoa.ShowDialog();
                            
                                btnTimKiem_Click(sender, e);
                                break;
                            default: //lỗi
                                MessageBox.Show(Code.StaticVariable.messeseboxLoi, Code.StaticVariable.messeseboxLuuY);
                                break;
                        }

                    }*/
                    btnTimKiem_Click(sender, e);
                    //this.dgvResult.Rows[this._currentSelectIndex].Selected = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Code.StaticVariable.messeseboxLuuY);
            }

        }
     
        #endregion

        #region hiển thị

        private void ShowHide_FunctionByPermission()
        {
            //string authcode = _code._services.GetAuthCode_ByGrpid_Menuid(Code.StaticVariable.groupID, Code.StaticVariable.menuID_Active);
            string authcode = _cl.GetAuthCodeMenuid(Code.StaticVariable.menuID_Active);
            char[] authcodes = authcode.ToCharArray();
            if (authcode.Length > 0)
            {
                for (int i = 0; i < authcodes.Length; i++)
                {
                    switch (i)
                    {
                        case 0:
                            if (authcodes[i] == 'Y')
                            {
                                this.btnAddNew.Enabled = true;
                            }
                            break;
                        case 1:
                            if (authcodes[i] == 'Y')
                            {
                                this.btnView.Enabled = true;
                            }
                            break;
                        case 2:
                            if (authcodes[i] == 'Y')
                            {
                                this.btnEdit.Enabled = true;
                            }
                            break;
                        case 3:
                            if (authcodes[i] == 'Y')
                            {
                                this.btnDelete.Enabled = true;
                            }
                            break;
                        case 4:
                            if (authcodes[i] == 'Y')
                            {
                                this.btnTimKiem.Enabled = true;
                            }
                            break;
                        case 5:
                            if (authcodes[i] == 'Y')
                            {
                                this.btnExport.Enabled = true;
                            }
                            break;
                        case 6:
                            if (authcodes[i] == 'Y')
                            {
                                this.btnApprove.Enabled = true;
                            }
                            break;
                        default:
                            break;
                    }
                }
            }
            else
            {
                MessageBox.Show(Code.StaticVariable.messeseboxFalsePermission, Code.StaticVariable.messeseboxLuuY);
            }
            
        }

        private bool GetPermission_byControl(Control c)
        {
            string authcode = _cl.GetAuthCodeMenuid(Code.StaticVariable.menuID_Active);
            char[] authcodes = authcode.ToCharArray();
            if (authcode.Length > 0)
            {
                if (c == this.btnAddNew && authcodes[0] == 'Y')
                    return true;
                else if (c == this.btnView && authcodes[1] == 'Y')
                    return true;
                else if (c == this.btnEdit && authcodes[2] == 'Y')
                    return true;
                else if (c == this.btnDelete && authcodes[3] == 'Y')
                    return true;
                else if (c == this.btnTimKiem && authcodes[4] == 'Y')
                    return true;
                else if (c == this.btnExport && authcodes[5] == 'Y')
                    return true;
                else if (c == this.btnApprove && authcodes[6] == 'Y')
                    return true;
                else
                    return false;
            }
            else
            {
                return false;
                MessageBox.Show(Code.StaticVariable.messeseboxFalsePermission, Code.StaticVariable.messeseboxLuuY);
            }
        }

        private void ShowResult(DataTable _e)
        {
            try
            {
                //convert _e to View
                bool duyet = false;
                DataTable view = new DataTable("View");
                foreach (DataColumn col in _e.Columns)
                {
                    if (col.ColumnName == "DUYET")
                    {
                        duyet = true;
                        view.Columns.Add(col.ColumnName, typeof(String));
                    }
                    else
                        view.Columns.Add(col.ColumnName, col.DataType);
                }

                for (int i = 0; i < _e.Rows.Count; i++)
                {
                    view.Rows.Add(_e.Rows[i].ItemArray);
                }

                //add duyet
                if (duyet)
                {
                    DataTable tblduyet = new DataTable("Duyet");
                    tblduyet = _code._services.GetDatatable_BySQL("select * from allcode where cdtype = 'AP' and cdname = 'DUYET' and cduser='Y' ORDER BY lstodr");
                    for (int i = 0; i < view.Rows.Count; i++)
                    {
                        for (int j = 0; j < tblduyet.Rows.Count; j++)
                        {
                            if (view.Rows[i]["DUYET"].ToString() == tblduyet.Rows[j]["CDVAL"].ToString())
                            {
                                view.Rows[i]["DUYET"] = tblduyet.Rows[j]["CDCONTENT"];
                                break;
                            }
                        }
                    }
                }

                // Thay tên dựa theo FieldCode, FieldName
                this.dgvResult.DataSource = view;

                foreach (DataGridViewColumn column in this.dgvResult.Columns)
                {
                    // kiem tra, neu column datatype = decimal --> format kieu khac
                    if (column.ValueType == typeof(System.Decimal))
                    {
                        column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                        column.DefaultCellStyle.Format = "#,##0.###";
                    }
                    foreach (DataRow row in _tableView.Rows)
                    {
                        if (row["fldname"].ToString() == column.HeaderText)
                        {
                            column.HeaderText = row["caption"].ToString();
                        }
                    }
                }

                //remove last empty row
                dgvResult.AllowUserToAddRows = false;
                //hien thi tong so row
                lb_Rowcount.Text = "Tổng số bản ghi của lần tìm kiếm là: " + this.dgvResult.Rows.Count;
                //set row header width = 50
                dgvResult.RowHeadersWidth = 50;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Code.StaticVariable.messeseboxLuuY);
            }
        }

        private bool Existed_DanhSachDieuKien(string _e)
        {
            for (int i = 0; i < this.clbDanhSachDieuKien.Items.Count; i++)
            {
                if (this.clbDanhSachDieuKien.Items[i].ToString().Contains(_e))
                {
                    return false;
                }
            }
            return true;
        }

        private void ShowHide_GiaTri(string _fieldtype, string _lookupcmdsql)
        {
            // Nếu _lookupcmdsql có giá trị, kiểu C thì tức là combobox
            if (_lookupcmdsql == "")
            {
                switch (_fieldtype)
                {
                    case "C":
                        this.txtGiaTriTimKiem.Visible = true;
                        this.cbbGiaTri.Visible = false;
                        this.dtpGiaTri.Visible = false;
                        break;
                    case "D":
                        this.txtGiaTriTimKiem.Visible = false;
                        this.cbbGiaTri.Visible = false;
                        this.dtpGiaTri.Visible = true;
                        break;
                    default:
                        break;
                }
            }
            else
            {
                switch (_fieldtype)
                {
                    case "C":
                        this.txtGiaTriTimKiem.Visible = false;
                        this.cbbGiaTri.Visible = true;
                        Show_ComboboxGiaTri();
                        this.dtpGiaTri.Visible = false;
                        break;
                    case "D":
                        this.txtGiaTriTimKiem.Visible = true;
                        this.cbbGiaTri.Visible = false;
                        this.dtpGiaTri.Visible = false;
                        break;
                    default:
                        break;
                }
            }
        }

        private void Show_ComboboxGiaTri()
        {
            DataTable _result = _code._services.GetDatatable_BySQL(_lookupcmdsql);
            //this.cbbGiaTri.Items.Clear();
            Dictionary<string, string> obj = new Dictionary<string, string>();
            foreach (DataRow row in _result.Rows)
            {
                //this.cbbGiaTri.Items.Add(row["DISPLAY"].ToString());

                obj.Add(row["VALUE"].ToString(), row["DISPLAY"].ToString());
                this.cbbGiaTri.DataSource = new BindingSource(obj, null);
                this.cbbGiaTri.DisplayMember = "Value";
                this.cbbGiaTri.ValueMember = "Key";
                this.cbbGiaTri.SelectedIndex = 0;
            }
            this.cbbGiaTri.SelectedIndex = 0;
        }

        void dgvResult_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {

            if (e.RowIndex % 2 == 0)
            {
                e.CellStyle.BackColor = Color.FromArgb(195, 231, 195);
            }
            else
            {
                e.CellStyle.BackColor = Color.FromArgb(253, 240, 208);
            }
        }

        private void Approve(string _ColumnName, string _id)
        {
            //Hiển thị Dialog thông báo
            DialogResult dialog = MessageBox.Show(Code.StaticVariable.messeseboxDuyetRow, Code.StaticVariable.messeseboxLuuY, MessageBoxButtons.YesNo);

            if (dialog == DialogResult.Yes)
            {
                //kiểm tra xem đã duyệt chưa?
                int check = _code._services.CheckApprove(_formName, _ColumnName, _id);
                //dữ liệu chưa được duyệt
                switch (check)
                {
                    case (int)Code.StaticVariable.approveCase.ChuaDuyet: //chưa duyêt

                        string _value = _ColumnName + "_" + _id;
                        DataTable _dt = new DataTable("duyetdata");
                        _dt = _cl._services.GetTableData_DuyetSua(_value, _formName);
                        if (_dt.Rows.Count > 0)//co du lieu da sua --> duyet sua
                        {
                            Forms.Frm_Duyet _Frm_Duyet = new Frm_Duyet(_ColumnName, _id, _dt, Code.StaticVariable.function_Edit, _formName);
                            _Frm_Duyet.ShowDialog();
                        }
                        else //ko co dl trong bang maintain_log --> them moi
                        {
                            //lay thong tin them moi
                            DataTable _dtAdd = new DataTable();
                            for (int i = 0; i < dgvResult.Columns.Count; i++)
                            {
                                DataColumn dc = new DataColumn(dgvResult.Columns[i].Name, typeof(String));
                                _dtAdd.Columns.Add(dc);
                            }

                            DataRow rowAdd = _dtAdd.NewRow();
                            for (int i = 0; i < dgvResult.Columns.Count; i++)
                            {
                                rowAdd[i] = dgvResult.CurrentRow.Cells[i].Value.ToString();
                            }
                            _dtAdd.Rows.Add(rowAdd);

                            //chuyen sang form duyet
                            Forms.Frm_Duyet _Frm_DuyetThemMoi = new Frm_Duyet(_ColumnName, _id, _dtAdd, Code.StaticVariable.function_AddNew, _formName);
                            _Frm_DuyetThemMoi.ShowDialog();

                        }
                        break;
                    case (int)Code.StaticVariable.approveCase.DaDuyet: //đã duyệt
                        MessageBox.Show(Code.StaticVariable.messeseboxDaDuyet, Code.StaticVariable.messeseboxLuuY);
                        break;
                    case (int)Code.StaticVariable.approveCase.DuyetXoa: //duyệt xoá
                        //thong tin xoa
                        DataTable _dtxoa = new DataTable();
                        for (int i = 0; i < dgvResult.Columns.Count; i++)
                        {
                            DataColumn dc = new DataColumn(dgvResult.Columns[i].Name, typeof(String));
                            _dtxoa.Columns.Add(dc);
                        }

                        DataRow row = _dtxoa.NewRow();
                        for (int i = 0; i < dgvResult.Columns.Count; i++)
                        {
                            row[i] = dgvResult.CurrentRow.Cells[i].Value.ToString();
                        }

                        _dtxoa.Rows.Add(row);

                        //chuyen sang form duyet xóa
                        Forms.Frm_Duyet _Frm_DuyetXoa = new Frm_Duyet(_ColumnName, _id, _dtxoa, Code.StaticVariable.function_Delete, _formName);
                        _Frm_DuyetXoa.ShowDialog();

                        break;
                    default: //lỗi
                        MessageBox.Show(Code.StaticVariable.messeseboxLoi, Code.StaticVariable.messeseboxLuuY);
                        break;
                }

            }
        }

        private bool ApproveAll(string _ColumnName, string _id)
        {
            bool b_result = true;
            //kiểm tra xem đã duyệt chưa?
            int check = _code._services.CheckApprove(_formName, _ColumnName, _id);
            //dữ liệu chưa được duyệt
            switch (check)
            {
                case (int)Code.StaticVariable.approveCase.ChuaDuyet: //chưa duyêt

                    string _value = _ColumnName + "_" + _id;
                    DataTable _dt = new DataTable("duyetdata");
                    _dt = _cl._services.GetTableData_DuyetSua(_value, _formName);
                    if (_dt.Rows.Count > 0)//co du lieu da sua --> duyet sua
                    {
                        // lay du lieu tu maintain_log --> 
                        string msg = this._cl._services.UpdateDataReal(_formName, _ColumnName, _id, Code.StaticVariable.userID);
                        //neu loi nem ra messagebox
                        if (msg != Code.StaticVariable.messeseboxSuaThanhCong)
                            throw new Exception(msg);
                        //sau khi update thanh cong , update truong duyet =1
                        bool b = _cl._services.Approve_Data(_formName, _ColumnName, _id, (int)Code.StaticVariable.approveCase.DaDuyet);
                        if (b)
                        {
                            //lưu vết giao dịch
                            _cl._services.WritetoTLLOG("",
                                                        Code.StaticVariable.userID,
                                                        Code.StaticVariable.menu_Code,
                                                        "",
                                                        _cl.Current_DATE("dd/MM/yyyy"),
                                                        "",
                                                        _cl.Current_DATE("hh:mm:ss"),
                                                        (int)Code.StaticVariable.approveCase.DaDuyet + "",
                                                        Code.StaticVariable.function_Approve,
                                                        _id,
                                                        "");
                            //luu vet nguoi thuc hien
                            _cl._services.Update_Last_Approve(_formName, _ColumnName, _id, Code.StaticVariable.userID);
                        }
                        else
                            b_result = false;
                    }
                    else //ko co dl trong bang maintain_log --> them moi
                    {
                        //duyet them moi
                        bool b = _cl._services.Approve_Data(_formName, _ColumnName, _id, (int)Code.StaticVariable.approveCase.DaDuyet);
                        if (b)
                        {
                            //lưu vết giao dịch
                            _cl._services.WritetoTLLOG("",
                                                        Code.StaticVariable.userID,
                                                        Code.StaticVariable.menu_Code,
                                                        "",
                                                        _cl.Current_DATE("dd/MM/yyyy"),
                                                        "",
                                                        _cl.Current_DATE("hh:mm:ss"),
                                                        (int)Code.StaticVariable.approveCase.DaDuyet + "",
                                                        Code.StaticVariable.function_Approve,
                                                        _id,
                                                        "");
                            //luu vet nguoi thuc hien
                            _cl._services.Update_Last_Approve(_formName, _ColumnName, _id, Code.StaticVariable.userID);

                        }
                        else
                            b_result = false;

                    }
                    break;
                case (int)Code.StaticVariable.approveCase.DaDuyet: //đã duyệt
                    break;
                case (int)Code.StaticVariable.approveCase.DuyetXoa: //duyệt xoá
                    string result = _cl._services.DeleteRow(_formName, _id, _ColumnName, Code.StaticVariable.userID);
                    if (result == "OK")
                    {
                        //lưu vết giao dịch ??? xem lại
                        _cl._services.WritetoTLLOG("",
                                                    Code.StaticVariable.userID,
                                                    Code.StaticVariable.menu_Code,
                                                    "",
                                                    _cl.Current_DATE("dd/MM/yyyy"),
                                                    "",
                                                    _cl.Current_DATE("hh:mm:ss"),
                                                    (int)Code.StaticVariable.approveCase.DuyetXoa + "",
                                                    Code.StaticVariable.function_Approve,
                                                    _id,
                                                    "");
                        //luu vet nguoi thuc hien
                        _cl._services.Update_Last_Approve(_formName, _ColumnName, _id, Code.StaticVariable.userID);
                    }
                    else
                        b_result = false;

                    break;
                default: //lỗi
                    b_result = false;
                    break;

            }
            return b_result;
        }
        #endregion


    }
}
